package cn.ffcs.uec.corp.action;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Components;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zkplus.databind.BindingListModelList;
import org.zkoss.zul.ListModelList;

import cn.ffcs.raptornuke.plugin.common.zk.ctrl.BasePortletComposer;
import cn.ffcs.uec.corp.action.bean.UecPsnCorpListMainBean;
import cn.ffcs.uec.corp.manager.UecPsnManager;
import cn.ffcs.uec.corp.model.UecPsnCorp;
import cn.ffcs.uom.common.util.ApplicationContextUtil;
import cn.ffcs.uom.common.util.NumericUtil;
import cn.ffcs.uom.common.vo.PageInfo;

@Controller
@Scope("prototype")
public class UecPsnCorpListMainComposer extends BasePortletComposer {

	private static final long serialVersionUID = -2497274555244653652L;

	private UecPsnCorpListMainBean bean = new UecPsnCorpListMainBean();

	private UecPsnCorp qryUecPsnCorp;
	
	private UecPsnManager uecPsnManager = (UecPsnManager) ApplicationContextUtil
			.getBean("uecPsnManager");

	
	
	/**
	 * 操作类型
	 */
	private String opType;

	@Override
	public void doAfterCompose(Component comp) throws Exception {
		super.doAfterCompose(comp);
		Components.wireVariables(comp, bean);
	}
	/**
	 * 初始化
	 */
	public void onCreate$uecPsnCorpListMainWin() {
		this.bindBean();
		this.onQueryUecPsnCorp();
	}
	/**
	 * 选择查询记录
	 * 
	 * @throws Exception
	 */
	public void onSelectRequest() throws Exception {
		if (this.bean.getUecPsnCorpListbox().getSelectedCount() > 0) {
			qryUecPsnCorp = (UecPsnCorp) bean.getUecPsnCorpListbox()
					.getSelectedItem().getValue();
			Events.postEvent("onOK", this.self, qryUecPsnCorp);
			this.onCancel();
		}
	}
	/**
	 * bindBean
	 */
	public void bindBean() {
		opType = (String) arg.get("opType");
		if ("PsnCorpList".equals(opType)) {
			this.bean.getUecPsnCorpListMainWin().setTitle("员工选择列表");
			qryUecPsnCorp = (UecPsnCorp) arg.get("qryUecPsnCorp");
			if (null != qryUecPsnCorp) {

			}
		}
	}

	/**
	 * 取消
	 */
	public void onCancel() {
		this.bean.getUecPsnCorpListMainWin().onClose();
	}
	/**
	 * 查询
	 */
	public void onQueryUecPsnCorp() {
		
		
		
		if (null != qryUecPsnCorp) {
			int activePage = bean.getUecPsnCorpListboxPaging().getActivePage();
			int pageSize = bean.getUecPsnCorpListboxPaging().getPageSize();
			PageInfo pageInfo = uecPsnManager
					.queryPageInfoByUecPsnCorp(qryUecPsnCorp, activePage + 1,
							pageSize);
			ListModelList dataList = new BindingListModelList(
					pageInfo.getDataList(), true);
			bean.getUecPsnCorpListbox().setModel(dataList);
			bean.getUecPsnCorpListboxPaging().setTotalSize(
					NumericUtil.nullToZero(pageInfo.getTotalCount()));
		}

	}
	/**
	 * 翻页
	 */
	public void onUecPsnCorpListboxPaging() {
		this.onQueryUecPsnCorp();
	}

	
	
}
